package com.newbelife.collector.web;

import com.newbelife.collector.util.InputMDC;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class IndexController {

    /**
     * [%d{yyyy-MM-dd'T'HH:mm:ss.SSSZZ}]
     * [%level{length=5}] 
     * [%thread-%tid] 
     * [%logger] 
     * [%X{hostName}] 
     * [%X{ip}] 
     * [%X{applicationName}] 
     * [%F,%L,%C,%M] 
     * [%m] ## '%ex'%n
     * -----------------------------------------------
     * [2020-12-27T23:43:26.975+08:00]
     * [INFO]
     * [main-1]
     * [org.apache.coyote.http11.Http11NioProtocol]
     * []
     * []
     * []
     * [DirectJDKLog.java,173,org.apache.juli.logging.DirectJDKLog,log]
     * [Starting ProtocolHandler ["http-nio-8001"]] ## ''
     * 
     * ["message", 
     * "\[%{NOTSPACE:currentDateTime}\] 
     *  \[%{NOTSPACE:level}\] 
     *  \[%{NOTSPACE:thread-id}\] 
     *  \[%{NOTSPACE:class}\] 
     *  \[%{DATA:hostName}\] 
     *  \[%{DATA:ip}\] 
     *  \[%{DATA:applicationName}\]
     *  \[%{DATA:location}\] 
     *  \[%{DATA:messageInfo}\] 
     *  ## (\'\'|%{QUOTEDSTRING:throwable})"]
     * @return
     */
    @RequestMapping(value = "/index")
    public String index() {
        InputMDC.putMDC();
        
        log.info("我是一条info日志");
        
        log.warn("我是一条warn日志");

        log.error("我是一条error日志");
        
        return "idx";
    }

    @RequestMapping(value = "/err")
    public String err() {
        InputMDC.putMDC();
        try {
            int a = 1/0;
        } catch (Exception e) {
            log.error("算术异常", e);
        }
        return "err";
    }
}
